package io.renren.common.utils;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketDemo {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("192.168.1.3",8989);
            socket.setSoTimeout(5 * 1000);
            OutputStream out = socket.getOutputStream();
            socket.setKeepAlive(true);
            InputStreamReader input = new InputStreamReader(socket.getInputStream());
            BufferedReader reader = new BufferedReader(input);

            OutputStreamWriter osw = new OutputStreamWriter(socket.getOutputStream());
            BufferedWriter writer = new BufferedWriter(osw);
            String lineString = null;
            writer.write("{\"msgType\":\"updateMsg\",\"txpower\":9}");
            writer.flush();
            while (null != (lineString = reader.readLine())) {
                System.out.println("-----lineString:-----\r\n"+lineString);
            }
            osw.close();
            writer.close();
            input.close();
            reader.close();
            socket.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
